/*
 * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
 * http://www.gnu.org/licenses/lgpl-3.0.html
 */

#ifndef CBWORKSPACE_H
#define CBWORKSPACE_H

#include <wx/string.h>
#include <wx/filename.h>

#include "globals.h"

/**
  * 实现功能: A workspace class.
  *
  * Workspaces are just collections of projects. By loading a workspace,
  * all the projects it contains are loaded.\n
  * There is always a workspace open. The default one does not contain any projects.\n
  * Currently, no inter-project dependencies are supported but at some point
  * they will be ;)
  *
  * 注释: The way WorkspaceLoader works now, requires that you save and delete the
  * loaded workspace *before* creating a new one...
  *
  * 功能:工作区类.
  * 工作区只是项目的集合.通过加载工作区,将加载它包含的所有项目.
  * 总有一个工作区打开.默认值不包含任何项目.
  * 目前,不支持项目间依赖项.但在某些情况下,它们将
  *
  * 注释:WorkspaceLoader现在的工作方式要求您在创建新工作区之前保存并删除加载的工作区...
  *
  */
class DLLIMPORT cbWorkspace
{
    public:
        /** 实现功能: Constructor
          * 参数说明: filename The file from which to load the workspace. If this
          *        parameter is empty, the default workspace is loaded.
          *
          * 实现功能: 构造函数
          * 参数说明:filename 从中加载工作区的文件.如果此参数为空,则加载默认工作区.
          */
        cbWorkspace(const wxString& filename = DEFAULT_WORKSPACE);

        /** 实现功能: Destructor */
        virtual ~cbWorkspace();

        /** 实现功能: Save the workspace
          * 参数说明: force If false (the default), the workspace will not be written to disk,
          * if it is not marked as modified.
          * 返回值:  True if saving succeeded, false if not.
          *
          * 实现功能: 保存工作区
          * 参数说明: force 如果为false(默认值),则工作区将不会写入磁盘(如果未标记为已修改).
          * 返回值:  如果保存成功则为True,否则为false.

          */
        virtual bool Save(bool force = false);

        /**
            * 实现功能: Save the workspace under a different filename
            * 参数说明: filename The name of the file to save.
            * 返回值:  True if saving succeeded, false if not.
            * 注释: If the filename parameter is empty, a file dialog to choose
            * the filename to save will be displayed.
            *
            * 实现功能: 以其他文件名保存工作区
            * 参数说明: filename 要保存的文件的名称.
            * 返回值:  如果保存成功则为True否则为false.
            * 注释:如果filename参数为空,将显示一个选择要保存的文件名的文件对话框.
          */
        virtual bool SaveAs(const wxString& filename);

        /**
            * 实现功能: Get the workspace file's name
            * 返回值:  The name of the file this workspace was loaded from.
            *
            * 实现功能:获取工作区文件的名称
            * 返回值:  从中加载此工作区的文件的名称.
          */
        virtual wxString GetFilename() const
        {
          return m_Filename.GetFullPath();
        }

        /**
          * 实现功能: Get the workspace's title
          * 返回值:  The title of the workspace.
          *
          * 实现功能: 获取工作区标题
          * 返回值:  工作区标题
          */
        virtual wxString GetTitle() const
        {
          return m_Title;
        }

        /**
            * 实现功能: Set the workspace's title
            * 参数说明: title The new title.
            *
            * 实现功能: 设置工作区标题
            * 参数说明: title 新标题.
          */
        virtual void SetTitle(const wxString& title);

        /**
            * 实现功能: Was this workspace loaded successfully?
            * 返回值:  True if the workspace was loaded successfully, false if not.
            * 注释: Because the only way to load a workspace is through its
            * constructor, and because we don't use exceptions, this is the only
            * way to know if loading succeeded.
            *
            * 实现功能: 是否已成功加载此工作区?
            * 返回值:  如果工作区加载成功,则为True否则为false.
            * 注释: 因为加载工作区的唯一方法是通过其构造函数,而且由于我们不使用异常,所以这是知道加载是否成功的唯一方法.
          */
        virtual bool IsOK() const { return m_IsOK; }

        /**
            * 实现功能: Is this workspace the Code::Blocks default?
            * 返回值:  True if the workspace is the default, false if not.
            *
            * 实现功能: 这个工作区是Code::Blocks的默认值吗?
            * 返回值:  如果工作区是默认值,则为True否则为false.
            *
          */
        virtual bool IsDefault() const { return m_IsDefault; }

        /**
         * 实现功能: Is this workspace modified?
          * 返回值:  True if the workspace is modified, false if not.
          * 注释: A workspace is considered modified when projects
          * are added-to/removed-from it, when the project's order
          * is changed or when the active project is changed.
          *
         * 实现功能: 这个工作区被修改了吗?
          * 返回值:  如果修改了工作区,则为True否则为false.
          * 注释: 将项目添加到工作区或从中删除项目,更改项目顺序或更改活动项目时,工作区将被视为已修改.
          */
        virtual bool GetModified() const { return m_Modified; }

        /**
            * 实现功能: Mark the workspace as modified or not
            * 参数说明: modified If true, the workspace will be marked as modified. If
            * false, the workspace will be marked as unmodified.
            *
            * 实现功能: 是否将工作区标记为已修改
            * 参数说明: 已修改如果为true,则工作区将标记为已修改.如果为false,则工作区将标记为未修改.
            *
          */
        virtual void SetModified(bool modified);

        /**
          * 实现功能: Set the preferred target for this workspace
          * 实现功能: 设置此工作区的首选目标
          */
        void SetPreferredTarget(const wxString &target);

        /**
         * 实现功能: Get the preferred target for this workspace
         * 实现功能: 获取此工作区的首选目标
          */
        wxString GetPreferredTarget() const;

        wxString GetWSPath() const { return m_WorkSpaceDir; }

        void ActiveProjectChanged();
        bool SaveLayout();
    private:

        // succeeded loading?
        // 加载成功?
        bool m_IsOK;
        // is this the Code::Blocks default workspace?
        // 这是Code::Blocks的默认工作区吗?
        bool m_IsDefault;
        // is it modified?
        // 是修改过的吗?
        bool m_Modified;
        // filename
        // 工作区文件名
        wxFileName m_Filename;
        wxString m_WorkSpaceDir;
        // title
        // 工作区标题
        wxString m_Title;
        wxString m_PreferredTargetName;
        // utility function
        //通用函数
        void Load();
        bool LoadLayout();
};

#endif // CBWORKSPACE_H
